﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy1_9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 初始化函数：设置热气球的初始位置、大小和图像

        private void initial()
        {
            pbBalloon.Width = 250;
            pbBalloon.Height = 250;
            pbBalloon.Left = 0;
            pbBalloon.Top = this.ClientSize.Height - pbBalloon.Height;
            pbBalloon.Image = Properties.Resources.热气球; // 资源中热气球图片的名称
            pbBalloon.SizeMode = PictureBoxSizeMode.StretchImage;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.BackgroundImage = Properties.Resources.flowers; // 资源中背景图片的名称
            this.BackgroundImageLayout = ImageLayout.Stretch; // 背景图拉伸填充窗体
            initial();
            timer1.Enabled = false;
        }

        // “开始”按钮点击事件：启动定时器
        private void btnStart_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        // 定时器Tick事件：控制热气球升空、缩小及重置
        private void timer1_Tick(object sender, EventArgs e)
        {
            // 热气球右上偏移并缩小
            pbBalloon.Top -= 5;
            pbBalloon.Left += 2;
            pbBalloon.Width -= 1;
            pbBalloon.Height -= 1;

            // 超出窗体2倍高度时，重置程序
            if (pbBalloon.Top < -this.ClientSize.Height)
            {
                timer1.Enabled = false;
                initial();
            }
        }
    }
}
